<%@page import="study.itwill.jsp.WebHandler"%>
<%@page import="study.itwill.team5.admin.AdminItem"%>
<%@page import="java.util.ArrayList"%>
<%@page import="study.itwill.common.DBHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page session="true" %>
<%
	WebHandler web = new WebHandler(request, response, out);
	AdminItem loginInfo = (AdminItem)session.getAttribute("ADMIN_INFO");
	
	// 로그인 정보가 없을 경우 로그인 페이지로 이동
	if (loginInfo == null) {
		web.goPage("/italia/login.jsp", "로그인이 필요합니다");
		return;
	}
%>
<%@ include file="../dbcon.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header">
		<h1>신규 관리자 계정 추가 - <small>새로운 계정을 추가하세요.</small></h1>
	</div>
		
		<form id="frmAdminAdd" class="form-horizontal" role="form" method="post" action="addAdminOk.jsp">
			<fieldset>
				
				<!-- 입력양식 -->
				<div class="form-group">
					<label for="admin_id" class="col-md-2 control-label">아이디</label>
					<div class="col-md-10">
						<input type="text" class="form-control" id="admin_id" placeholder="아이디를 입력하세요" name="admin_id" autofocus>
					</div>
				</div>
				
				<div class="form-group">
					<label for="admin_pw" class="col-md-2 control-label">비밀번호</label>
					<div class="col-md-10">
						<input type="password" class="form-control" id="admin_pw" placeholder="비밀번호를 입력하세요" name="admin_pw">
					</div>
				</div>
				
				<div class="form-group">
					<label for="admin_level" class="col-md-2 control-label">레벨</label>
					<div class="col-md-10">
						<select class="form-control" id="admin_level" name="admin_level">
							<option> ---- 선택하세요 ---- </option>
							<option value="1">1 level</option>
							<option value="2">2 level</option>
							<option value="3">3 level</option>
							<option value="4">4 level</option>
							<option value="5">5 level</option>
						</select>
					</div>
				</div>
				
				<div class="form-group">
					<label for="admin_comment" class="col-md-2 control-label">코멘트</label>
					<div class="col-md-10">
						<input type="text" class="form-control" id="admin_comment" placeholder="코멘트를 입력하세요" name="admin_comment">
					</div>
				</div>
				
				<div class="form-group">
					<div class="col-md-offset-2 col-md-10">
						<div class="row">
							<div class="col-md-6">
								<button type="submit" class="btn btn-primary btn-block">저장하기</button>
							</div>
							<div class="col-md-6">
								<button type="reset" class="btn btn-warning btn-block">다시작성</button>
							</div>
						</div>
						
					</div>
				</div>
			</fieldset>
		</form>
	</div>
	<% DBHandler.disconnect(); %>
	<!-- Javascript -->
	<script src="/italia/assets/js/jquery.js"></script>
	<script src="/italia/assets/js/bootstrap.min.js"></script>
	<!-- 형식검사 클래스 참조 -->
	<script src="/italia/assets/js/string.js"></script>
	<!-- 구현부분 -->
	<script type="text/javascript">
		// jquery main()
		$(function() {
			$("#frmAdminAdd").submit(function() {
				
				// 아이디 입력여부 검사
				if (!$("input[name='admin_id']").val().isValue()) {
					alert("아이디를 입력하세요.");
					$("input[name='admin_id']").focus();
					return false;
				}
				
				// 아이디 형식 검사
				if (!$("input[name='admin_id']").val().isAlphabetNum()) {
					alert("아이디는 영어와 숫자로만 입력 가능합니다.");
					$("input[name='admin_id']").focus();
					return false;
				}
				
				// 비밀번호 입력여부 검사
				if (!$("input[name='admin_pw']").val().isValue()) {
					alert("비밀번호를 입력하세요.");
					$("input[name='admin_pw']").focus();
					return false;
				}
				
				// 비밀번호 형식 검사
				if (!$("input[name='admin_pw']").val().isAlphabetNum()) {
					alert("비밀번호는 영어와 숫자로만 입력 가능합니다.");
					$("input[name='admin_pw']").focus();
					return false;
				}
				
				// 레벨 선택여부 검사
				if ($("select[name='admin_level'] > option:selected").index() < 1) {
					alert("레벨을 입력하세요.");
					$("select[name='admin_level']").focus();
					return false;
				}
				
				// 코멘트 입력여부 검사
				if (!$("input[name='admin_comment']").val().isValue()) {
					alert("코멘트를 입력하세요.");
					$("input[name='admin_comment']").focus();
					return false;
				}
			});
		});
	</script>
  </body>
</html>